//
//  WLRouterInternetSubController.m
//  WanLian
//
//  Created by muzhuang on 2018/10/18.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLRouterInternetSubController.h"
#import "WLRouterNetSetCell.h"
#import "AppDelegate.h"
#import "WLRouterRestartView.h"

@interface WLRouterInternetSubController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>//,RouterSocketDelegate>
{
    UIButton *btnSave;
    BOOL    isShowed;
}

@property (nonatomic, strong) UITableView   *tbNetWork;
@property (nonatomic, assign) NSInteger     netConfig;//0:auto,1manual
@property (nonatomic, copy) NSDictionary    *dictPPPOE;
@property (nonatomic, copy) NSDictionary    *dictStatic;
@property (nonatomic, copy) NSDictionary    *dictDynamic;

@end

@implementation WLRouterInternetSubController

- (void)dealloc
{
//    [[WLSocketManager sharedSocketManager] removeDelegate:self];
    [[WLSocketManager sharedSocketManager] removeDelegate:self delegateQueue:dispatch_get_main_queue()];
}

//- (void)viewDidAppear:(BOOL)animated
//{
//    [super viewDidAppear:animated];
//    [self receiveRouterConnectSet];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    _netConfig = _netModel.dynamicType;
    _tbNetWork = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tbNetWork.backgroundColor = wlUIColorRGB(0xFAFAFA);
    _tbNetWork.delegate = self;
    _tbNetWork.dataSource = self;
    _tbNetWork.rowHeight = WLScaleX(58);
    if (@available(iOS 11.0, *)) {
        _tbNetWork.estimatedSectionHeaderHeight = 0;
        _tbNetWork.estimatedSectionFooterHeight = 0;
    }
    [self.view addSubview:_tbNetWork];
    _tbNetWork.scrollEnabled = NO;
    WLWkSelf
    [_tbNetWork mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
    
//    [[WLSocketManager sharedSocketManager] addDelegate:self];
    [[WLSocketManager sharedSocketManager] addDelegate:self delegateQueue:dispatch_get_main_queue()];
    
    btnSave = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16), 0, WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(47))];
//    CAGradientLayer *gradientBtn = [CAGradientLayer layer];
//    gradientBtn.frame = _btnLogin.bounds;  // 设置显示的frame
//    gradientBtn.colors = @[(__bridge id)wlUIColorRGB(0x1A59E2).CGColor,(__bridge id)wlUIColorRGB(0x2292F5).CGColor]; // 设置渐变颜色
//    gradientBtn.startPoint = CGPointMake(0, 0);
//    gradientBtn.endPoint = CGPointMake(1, 0);
//    [_btnLogin.layer insertSublayer:gradientBtn atIndex:0];
    
    btnSave.layer.cornerRadius = 5;//WLScaleX(5);
    btnSave.layer.masksToBounds = YES;
    btnSave.titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:16];
    [btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnSave addTarget:self action:@selector(saveSettingAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnSave];
    if (self.netType==0)
    {
        btnSave.frame = CGRectMake(WLScaleX(16), WLScaleX(20+116+40), WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(47));
        [btnSave setTitle:@"拨号连接" forState:UIControlStateNormal];
//        btnSave.backgroundColor = wlUnderlineColor;
        [WLCommonTool addGradientColor:btnSave fromColor:wlblueColor toColor:wlUIColorRGB(0x2292F5)];
    }
    else if (self.netType==1)
    {
        btnSave.frame = CGRectMake(WLScaleX(16), WLScaleX(20+58*5+40), WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(47));
        [WLCommonTool addGradientColor:btnSave fromColor:wlblueColor toColor:wlUIColorRGB(0x2292F5)];
        [btnSave setTitle:@"保存设置" forState:UIControlStateNormal];
    }
    else
    {
        btnSave.frame = CGRectMake(WLScaleX(16), WLScaleX(20+100+58+40), WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(47));
        [WLCommonTool addGradientColor:btnSave fromColor:wlblueColor toColor:wlUIColorRGB(0x2292F5)];
        [btnSave setTitle:@"保存设置" forState:UIControlStateNormal];
    }
    [self receiveRouterConnectSet];
}

- (void)receiveRouterConnectGetAgain
{
    if (self.netType==0&&self.dictPPPOE==nil)
    {
        NSDictionary *dict = @{@"type":@"DEVICE_PPPOEGET_REQ",@"content":@""};
        [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
    }
    else if (self.netType==1&&self.dictStatic==nil)
    {
        NSDictionary *dict = @{@"type":@"DEVICE_STATICGET_REQ",@"content":@""};
        [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
    }
    else if (self.netType==2&&self.dictDynamic==nil)
    {
        NSDictionary *dict = @{@"type":@"DEVICE_DYNAMICGET_REQ",@"content":@""};
        [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
    }
}

- (void)receiveRouterConnectSet
{
    NSDictionary *dict;
    if (self.netType==0) {
        dict = @{@"type":@"DEVICE_PPPOEGET_REQ",@"content":@""};
    }
    else if (self.netType==1)
    {
        dict = @{@"type":@"DEVICE_STATICGET_REQ",@"content":@""};
    }
    else
    {
        dict = @{@"type":@"DEVICE_DYNAMICGET_REQ",@"content":@""};
    }
    [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
}

#pragma mark - 接收消息代理
- (void)didReceiveMessage:(WLSocketModel *)msgModel withTag:(long)tag
{
    if ([msgModel.type isEqualToString:@"DEVICE_PPPOEGET_REP"])
    {
        if (msgModel.content != nil) {
            NSData *jsonData = [msgModel.content dataUsingEncoding:NSUTF8StringEncoding];
            NSError *err;
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                                options:NSJSONReadingMutableContainers
                                                                  error:&err];
            self.dictPPPOE = dic;
            [self.tbNetWork reloadData];
        }
    }
    else if ([msgModel.type isEqualToString:@"DEVICE_STATICGET_REP"])
    {
        if (msgModel.content != nil) {
            NSData *jsonData = [msgModel.content dataUsingEncoding:NSUTF8StringEncoding];
            NSError *err;
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                                options:NSJSONReadingMutableContainers
                                                                  error:&err];
            self.dictStatic = dic;
            [self.tbNetWork reloadData];
        }
    }
    else if ([msgModel.type isEqualToString:@"DEVICE_DYNAMICGET_REP"])
    {
        if (msgModel.content != nil) {
            NSData *jsonData = [msgModel.content dataUsingEncoding:NSUTF8StringEncoding];
            NSError *err;
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                                options:NSJSONReadingMutableContainers
                                                                  error:&err];
            self.dictDynamic = dic;
            _netConfig = [dic[@"dType"] integerValue];
            [self.tbNetWork reloadData];
        }
    }
    else if ([msgModel.type isEqualToString:@"COMMON_SUCCESS"])
    {
//        [self showHUDMessage:@"设置成功"];
        if (isShowed)
        {
            [[WLSocketManager sharedSocketManager] userManualdisconnect];
            isShowed = NO;
            WLWkSelf
            WLRouterRestartView *restartView = [[WLRouterRestartView alloc] init];
            restartView.okAction = ^{
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            };
            [restartView show];
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            [userDefaults setObject:[NSDate date] forKey:@"restartTime"];
            [userDefaults synchronize];
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            [appDelegate linkRouterTest:30];
        }
    }
}

-(void)saveSettingAction
{
    [self.view endEditing:YES];
    NSString *strLineOne;
    NSString *strLineTwo;
    NSString *strLineThird;
    NSString *strLineFour;
    NSString *strLineFive;
    for (int i = 0; i<5; i++)
    {
        if (self.netType==0&&i>=2)
        {
            break;
        }
        if (self.netType==2) {
            if (i==0) {
                continue;
            }
            if (i>=3) {
                break;
            }
        }
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        WLRouterNetSetCell *cell = (WLRouterNetSetCell *)[self.tbNetWork cellForRowAtIndexPath:indexPath];
        if (i==0) {
            strLineOne = cell.textNetInfo.text;
        }
        else if (i==1)
        {
            strLineTwo = cell.textNetInfo.text;
        }
        else if (i==2)
        {
            strLineThird = cell.textNetInfo.text;
        }
        else if (i==3)
        {
            strLineFour = cell.textNetInfo.text;
        }
        else if (i==4)
        {
            strLineFive = cell.textNetInfo.text;
        }
    }
    
//    NSDictionary *paramNet;
//    WLWkSelf
    if (self.netType==0)
    {
        if (strLineOne.length<1)//||strLineOne.length>20)
        {
            [self showHUDMessage:@"请输入宽带帐号"];
            return;
        }
        else if (strLineTwo.length<1)//||strLineTwo.length>16)
        {
            [self showHUDMessage:@"请输入宽带密码"];
        }
        NSDictionary *dictContent = @{@"username":strLineOne,@"password":strLineTwo};
        NSError *parseError;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictContent options:NSJSONWritingPrettyPrinted error:&parseError];
        NSString *strContent = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        NSDictionary *dict = @{@"type":@"DEVICE_PPPOE_SET",@"content":strContent};
        [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
//        NSDictionary *paramsp = @{@"networkAccount":strLineOne,@"networkPassWord":strLineTwo};
//        [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"device/config/call" withParamsDic:paramsp success:^(NSDictionary *successDict) {
//            [weakSelf showHUDMessage:successDict[@"message"]];
//        } failure:^(NSString *errorMsg, NSInteger errorTag) {
//            [weakSelf showHUDMessage:errorMsg];
//        } error:^(NSError *error) {
//
//        } inView:self.view];
    }
    else if (self.netType==1)
    {
        if ([WLCommonTool isIPAddress:strLineOne]==NO)//(strLineOne.length<1)
        {
            [self showHUDMessage:@"请输入正确的网络地址"];
            return;
        }
        else if ([WLCommonTool isIPAddress:strLineTwo]==NO) {
            [self showHUDMessage:@"请输入正确的子网掩码"];
            return;
        }
        else if ([WLCommonTool isIPAddress:strLineThird]==NO) {
            [self showHUDMessage:@"请输入正确的默认网关"];
            return;
        }
        else if ([WLCommonTool isIPAddress:strLineFour]==NO) {
            [self showHUDMessage:@"请输入正确的首选DNS"];
            return;
        }
        else if (strLineFive.length>0)
        {
            if ([WLCommonTool isIPAddress:strLineFour]==NO) {
                [self showHUDMessage:@"请输入正确的备选DNS"];
                return;
            }
        }
//        paramNet = @{@"sord":@"static",@"static_webAddress":strLineOne,@"static_subnetMask":strLineTwo,@"static_defaultNetWay":strLineThird,@"oneDNS":strLineFour,@"twoDNS":strLineFive};
        NSDictionary *dictContent = @{@"ip":strLineOne,@"child":strLineTwo,@"wlan":strLineThird,@"dns1":strLineFour,@"dns2":strLineFive};
        NSError *parseError;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictContent options:NSJSONWritingPrettyPrinted error:&parseError];
        NSString *strContent = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        NSDictionary *dict = @{@"type":@"DEVICE_NET_STATIC_SET",@"content":strContent};
        [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
    }
    else if (self.netType==2)
    {
        NSDictionary *dictContent = @{@"dType":@(_netConfig)};
        if (_netConfig==1)
        {
            if ([WLCommonTool isIPAddress:strLineTwo]==NO)// strLineTwo.length<1)
            {
                [self showHUDMessage:@"请输入正确的首选DNS"];
                return;
            }
            if (strLineThird.length>0) {
                if ([WLCommonTool isIPAddress:strLineThird]==NO)
                {
                    [self showHUDMessage:@"请输入正确的备选DNS"];
                    return;
                }
            }
            dictContent = @{@"dType":@(_netConfig),@"dns1":strLineTwo,@"dns2":strLineThird};
        }
//        NSDictionary *dictContent = @{@"dType":@(_netConfig),@"dns1":strLineTwo,@"dns2":strLineThird};
        NSError *parseError;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictContent options:NSJSONWritingPrettyPrinted error:&parseError];
        NSString *strContent = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        NSDictionary *dict = @{@"type":@"DEVICE_NET_DYMIC_SET",@"content":strContent};
        [[WLSocketManager sharedSocketManager] sendMessage:dict timeOut:-1 tag:0];
//        paramNet = @{@"sord":@"dynamic",@"dynamicType":@(_netConfig),@"oneDNS":strLineTwo,@"twoDNS":strLineThird};
    }
    isShowed = YES;
//    [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"device/config/edit" withParamsDic:paramNet success:^(NSDictionary *successDict) {
//        [weakSelf showHUDMessage:successDict[@"message"]];
//    } failure:^(NSString *errorMsg, NSInteger errorTag) {
//        [weakSelf showHUDMessage:errorMsg];
//    } error:^(NSError *error) {
//
//    } inView:self.view];
}

#pragma mark - UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return WLScaleX(20);
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.netType==0) {
        return 2;
    }
    if (self.netType==1) {
        return 5;
    }
    else
    {
        return 3;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.netType==2&&indexPath.row==0) {
        return WLScaleX(42);
    }
    return WLScaleX(58);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = indexPath.row;
    static NSString *strNet = @"netCell";
    WLRouterNetSetCell *cell = [tableView dequeueReusableCellWithIdentifier:strNet];
    if (!cell) {
        cell = [[WLRouterNetSetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strNet];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.textLabel.font = [WLCommonTool fontTypePingFangSCRegular:17];
//        cell.textLabel.textColor = wlBlackColor;
    }
    
    cell.textNetInfo.text = @"";
    cell.textNetInfo.enabled = YES;
    cell.accessoryView = nil;
    if (self.netType==0)
    {
//        WLLog(@"____dict:%@,%@,%@",self.dictPPPOE,self.dictStatic,self.dictDynamic);
        cell.labTitle.frame = CGRectMake(16, WLScaleX(16), 40, WLScaleX(26));
        cell.textNetInfo.frame = CGRectMake(WLScaleX(16)+46, WLScaleX(5), WIDTH_SCREEN_WL-WLScaleX(32)-46, WLScaleX(48));
        if (row==0) {
            cell.labTitle.text = @"账号";
            cell.textNetInfo.placeholder = @"请输入宽带账号";
            cell.textNetInfo.text = self.dictPPPOE[@"username"];
//            if (_netModel.networkAccount) {
//                cell.textNetInfo.text = _netModel.networkAccount;
//            }
        }
        else
        {
            cell.labTitle.text = @"密码";
            cell.textNetInfo.placeholder = @"请输入宽带密码";
            cell.textNetInfo.text = self.dictPPPOE[@"password"];
//            if (_netModel.networkPassWord) {
//                cell.textNetInfo.text = _netModel.networkPassWord;
//            }
            cell.textNetInfo.secureTextEntry = YES;
            UIButton *btnEye = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
            [btnEye setImage:[UIImage imageNamed:@"eye_net_close"] forState:UIControlStateNormal];
            [btnEye setImage:[UIImage imageNamed:@"eye_net_open"] forState:UIControlStateSelected];
            [btnEye addTarget:self action:@selector(openOrCloseAction:) forControlEvents:UIControlEventTouchUpInside];
            btnEye.selected = NO;
            cell.accessoryView = btnEye;
        }
    }
    else if (self.netType==1)
    {
        cell.labTitle.frame = CGRectMake(16, WLScaleX(16), WLScaleX(75), WLScaleX(26));
        cell.textNetInfo.frame = CGRectMake(WLScaleX(105), WLScaleX(5), WIDTH_SCREEN_WL-WLScaleX(105+16), WLScaleX(48));
        if (row==0) {
            cell.labTitle.text = @"网络地址";
            cell.textNetInfo.placeholder = @"请输入网络地址";
            cell.textNetInfo.text = self.dictStatic[@"ip"];
//            if (_netModel.static_webAddress) {
//                cell.textNetInfo.text = _netModel.static_webAddress;
//            }
        }
        else if (row==1)
        {
            cell.labTitle.text = @"子网掩码";
            cell.textNetInfo.placeholder = @"请输入子网掩码";
            cell.textNetInfo.text = self.dictStatic[@"child"];
//            if (_netModel.static_subnetMask) {
//                cell.textNetInfo.text = _netModel.static_subnetMask;
//            }
        }
        else if (row==2)
        {
            cell.labTitle.text = @"默认网关";
            cell.textNetInfo.placeholder = @"请输入默认网关";
            cell.textNetInfo.text = self.dictStatic[@"wlan"];
//            if (_netModel.static_defaultNetWay) {
//                cell.textNetInfo.text = _netModel.static_defaultNetWay;
//            }
        }
        else if (row==3)
        {
            cell.labTitle.text = @"首选DNS";
            cell.textNetInfo.placeholder = @"请输入首选DNS";
            cell.textNetInfo.text = self.dictStatic[@"dns1"];
//            if (_netModel.oneDNS) {
//                cell.textNetInfo.text = _netModel.oneDNS;
//            }
            
            UILabel *labMust = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
            labMust.font = [WLCommonTool fontTypePingFangSCRegular:12];
            labMust.textColor = wlUnderlineColor;
            labMust.textAlignment = NSTextAlignmentCenter;
            labMust.text = @"必填";
            cell.accessoryView = labMust;
        }
        else
        {
            cell.labTitle.text = @"备选DNS";
            cell.textNetInfo.placeholder = @"请输入备选DNS";
            cell.textNetInfo.text = self.dictStatic[@"dns2"];
//            if (_netModel.twoDNS) {
//                cell.textNetInfo.text = _netModel.twoDNS;
//            }
            
            UILabel *labMust = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
            labMust.font = [WLCommonTool fontTypePingFangSCRegular:12];
            labMust.textColor = wlUnderlineColor;
            labMust.textAlignment = NSTextAlignmentCenter;
            labMust.text = @"选填";
            cell.accessoryView = labMust;
        }
    }
    else
    {
        if (row==0)
        {
            static NSString *strConfig = @"cellConfig";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strConfig];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strConfig];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            for (UIView *subView in cell.contentView.subviews) {
                [subView removeFromSuperview];
            }
            NSArray *arrTitles = @[@" 自动配置DNS",@" 手动配置DNS"];
            for (int i=0; i<arrTitles.count; i++)
            {
                UIButton *btnType = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16)+i*(130+WLScaleX(15)), 0, 130, WLScaleX(42))];
                [btnType setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
                [btnType setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
                btnType.titleLabel.font = [WLCommonTool fontTypePingFangSCRegular:16];
                [btnType setTitleColor:wlBlackColor forState:UIControlStateNormal];
                [btnType setTitle:arrTitles[i] forState:UIControlStateNormal];
                btnType.tag = 100+i;
                [btnType addTarget:self action:@selector(netDNSConfigAction:) forControlEvents:UIControlEventTouchUpInside];
                if (self.netConfig==i) {
                    btnType.selected = YES;
                }
                [cell.contentView addSubview:btnType];
            }
            return cell;
        }
        else
        {
            cell.labTitle.frame = CGRectMake(16, WLScaleX(16), WLScaleX(75), WLScaleX(26));
            cell.textNetInfo.frame = CGRectMake(WLScaleX(105), WLScaleX(5), WIDTH_SCREEN_WL-WLScaleX(105+16), WLScaleX(48));
            if (_netConfig==0)
            {
                cell.textNetInfo.enabled = NO;
                if (row==1)
                {
                    cell.labTitle.text = @"首选DNS";
                    cell.textNetInfo.placeholder = @"系统自动分配DNS";
//                    cell.textNetInfo.text = self.dictDynamic[@"dns1"];
//                    if (_netModel.oneDNS) {
//                        cell.textNetInfo.text = _netModel.oneDNS;
//                    }
                }
                else
                {
                    cell.labTitle.text = @"备选DNS";
                    cell.textNetInfo.placeholder = @"系统自动分配DNS";
//                    cell.textNetInfo.text = self.dictDynamic[@"dns2"];
//                    if (_netModel.twoDNS) {
//                        cell.textNetInfo.text = _netModel.twoDNS;
//                    }
                }
            }
            else
            {
                if (row==1)
                {
                    cell.labTitle.text = @"首选DNS";
                    cell.textNetInfo.placeholder = @"请输入首选DNS";
                    cell.textNetInfo.text = self.dictDynamic[@"dns1"];
//                    if (_netModel.oneDNS) {
//                        cell.textNetInfo.text = _netModel.oneDNS;
//                    }
                    
                    UILabel *labMust = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
                    labMust.font = [WLCommonTool fontTypePingFangSCRegular:12];
                    labMust.textColor = wlUnderlineColor;
                    labMust.textAlignment = NSTextAlignmentCenter;
                    labMust.text = @"必填";
                    cell.accessoryView = labMust;
                }
                else
                {
                    cell.labTitle.text = @"备选DNS";
                    cell.textNetInfo.placeholder = @"请输入备选DNS";
                    cell.textNetInfo.text = self.dictDynamic[@"dns2"];
//                    if (_netModel.twoDNS) {
//                        cell.textNetInfo.text = _netModel.twoDNS;
//                    }
                    UILabel *labOption = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
                    labOption.font = [WLCommonTool fontTypePingFangSCRegular:12];
                    labOption.textColor = wlUnderlineColor;
                    labOption.textAlignment = NSTextAlignmentCenter;
                    labOption.text = @"选填";
                    cell.accessoryView = labOption;
                }
            }
        }
    }
    
    return cell;
}

- (void)openOrCloseAction:(UIButton *)btnEye
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    WLRouterNetSetCell *cell = (WLRouterNetSetCell *)[self.tbNetWork cellForRowAtIndexPath:indexPath];
    cell.textNetInfo.secureTextEntry = btnEye.selected;
    btnEye.selected = !btnEye.selected;
}

- (void)netDNSConfigAction:(UIButton *)btnConfig
{
    self.netConfig = btnConfig.tag-100;
    [_tbNetWork reloadData];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
